﻿Chenxin.UI.ApplyInfoManage = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/logic/ShowListBargain.ashx',
    createGrid: function() {
        // return new Chenxin.UI.Pagination({
        // actionUrl: this.actionUrl + '?op=getlist',
        // pageSize: 10,
        // renderTo: 'applyinfo_table',
        // id: 'applyinfo'
        // });
        var _this = this;
        _this.showtype = 10;
        return new Chenxin.UI.MultiRowGrid({
            actionUrl: this.actionUrl + '?op=getmultilist',
            pageSize: 50,
            height: 400,
            renderTo: 'applyinfo_table',
            hasCheckBox: false,
            id: 'applyinfo',
            title: '成交记录列表',
            baseParam: { showtype: 10 },
            scope: this,
            autoLoad: false,
            cellAlign: 'left',
            createTitleTool: function() {
                return [{
                    text: '<span class="simple"></span>主营业务(买卖)',
                    scope: _this,
                    title: '买卖业务',
                    handler: function(el) {
                        this.showTypeGrid(10, el.title);
                        _this.showtype = 10;
                    }
                }, {
                    text: '<span class="simple"></span>主营业务(租赁)',
                    scope: _this,
                    title: '租赁业务',
                    handler: function(el) {
                        this.showTypeGrid(20, el.title);
                        _this.showtype = 20;
                    }
                }, {
                    text: '<span class="simple"></span>零散业务',
                    scope: _this,
                    title: '零散业务',
                    handler: function(el) {
                        this.showTypeGrid(30, el.title);
                        _this.showtype = 30;
                    }
                }, {
                    text: '<span class="simple"></span>其他业务',
                    scope: _this,
                    title: '其他业务',
                    handler: function(el) {
                        this.showTypeGrid(40, el.title);
                        _this.showtype = 40;
                    }
                }, {
                    text: '<span id="" class="x-grid-export" style="width:90px" title="导出全部数据">导出全部数据</span>',
                    scope: this,
                    title: '导出全部数据',
                    handler: function(el) {
                        _this.exportAll();
                    }
}];
                },
                modelId: 'ContractId'
            })
        },
        showTypeGrid: function(showtype, title) {
            showtype = showtype || 10;
            if (this.grid.baseParam.showtype != showtype) {
                this.grid.baseParam.showtype = showtype;
                this.grid.reload();
                this.grid.setTitle(title + '列表');
            }
        },
        cancle: function() {
        },
        exportAll: function() {
            _this = this;
            paramStr = this.search.getParamJson();
            paramStr.op = 'exportAll';
            paramStr.showtype = _this.showtype;
            Chenxin.Msg.Waiting.show();
            Chenxin.Fn.exportToExcelByServer(this.actionUrl, paramStr, '导出文件');
            //$.ajax({ url: this.actionUrl, data: paramStr,async:false});
            Chenxin.Msg.Waiting.hide();
            /*
            Chenxin.ajax({
            type: "get",
            dataType: "json",
            url: this.actionUrl,
            data: paramStr,
            onSuccess: function(data) {
            Chenxin.Msg.Waiting.hide();
            //Chenxin.Fn.exportToExcel(data, '导出文件');
            },
            onError: function(data) {
            Chenxin.Msg.Waiting.hide();
            alert(data.msg);
            }
            });*/
        },
        loadInfo: function() {
            var _this = this;
            Chenxin.ajax({
                type: "get",
                dataType: "text",
                paramType: 'json',
                async: false,
                url: this.actionUrl,
                data: { op: 'getmodel', modelid: this.currentId },
                onSuccess: function(data, msg) {
                    if (data) {
                        _this.currentInfo = data.model;
                    }
                }
            });
        },
        loadLitInfo: function() {
            var _this = this;
            Chenxin.ajax({
                type: "get",
                dataType: "text",
                paramType: 'json',
                async: false,
                url: '/service/logic/ShowListLitigation.ashx',
                data: { op: 'getdepart' },
                onSuccess: function(data, msg) {
                    if (data) {
                        _this.currentLitInfo = data;
                    }
                }
            });
        },
        loadNotLitInfo: function() {
            var _this = this;
            Chenxin.ajax({
                type: "get",
                dataType: "text",
                paramType: 'json',
                async: false,
                url: '/service/logic/ShowListNotLitigation.ashx',
                data: { op: 'getdepart' },
                onSuccess: function(data, msg) {
                    if (data) {
                        _this.currentNotLitInfo = data;
                    }
                }
            });
        },
        loadRemark: function() {
            var _this = this;
            Chenxin.ajax({
                type: "get",
                dataType: "text",
                paramType: 'json',
                async: false,
                url: '/service/logic/ShowRemarkInfo.ashx',
                data: { op: 'searchRemark', modelid: this.currentId },
                onSuccess: function(data, msg) {
                    if (data) {
                        _this.currentRemark = data;
                    }
                }
            });
        },
        updateInfo: function() {
            var _this = this;
            if (!_this.currentId) {
                alert('请先选择一条成交记录！');
                return;
            }

            Chenxin.ajax({
                type: "post",
                dataType: "text",
                paramType: 'json',
                url: this.actionUrl,
                data: { op: 'updatestatus', modelid: this.currentId, flg: _this.Flg },
                onSuccess: function(data, msg) {
                    if (msg) {
                        alert(msg);
                    }
                    _this.grid.reload();
                }
            });
        },
        initEvent: function() {
            var _this = this;
            //底部按钮点击事件
            $('.LeftFooter a').click(function() {
                _this.bindBottomBar(this);
            });
        },
        bindBottomBar: function(obj) {
            _this = this;
            switch (obj.name) {
                //收付开单                                
                case "BillPayment":
                    if (!this.currentId) {
                        alert('请选择一条成交记录！');
                        return;
                    }
                    this.addBillPayment();
                    break;
                //应收登记                
                case "RegIncome":
                    this.RegIncome();
                    break;
                //个案补证                               
                case "AddCertificates":
                    if (!this.currentId) {
                        alert('请选择一条成交记录！');
                        return;
                    }
                    //个案补证
                    this.getLackItemsInfo();
                    break;
                //上传附件                                   
                case "AddAttachment":
                    this.UploadFile();
                    break;
                //封帐                
                case "CloseAccount":
                    if (_this.grid.getCurrentRecord().LockStatus == 255) {
                        alert('该记录已封帐，不能再次封帐！');
                        return;
                    }
                    _this.Flg = 255;
                    this.del('closeaccount', '是否封帐该记录？', '', { flg: _this.Flg });
                    break;
                //生成业绩                
                case "ProduceFeat":
                    this.ProduceFeat();
                    break;
                //取消业绩                
                case "CancelFeat":
                    this.CancelFeat();
                    break;
                //编辑                
                case "aEdit":
                    if (!_this.currentId) {
                        alert('请先选择一条成交记录！');
                        return;
                    }
                    if (_this.grid.getCurrentRecord().bArchivement && _this.grid.getCurrentRecord().LockStatus == 255) {
                        alert('该记录已生成业绩并且已封帐，不能修改！');
                        return;
                    }
                    switch (_this.grid.getCurrentRecord().BusinessType) {
                        case 10:
                        case 20:
                            _this.toCheckPermit('confirmedit', '/page/Contract_ApplyInfo/MainBusinessApply.aspx');
                            break;
                        case 30:
                            _this.toCheckPermit('confirmedit', '/page/Contract_ApplyInfo/LooseBusinessApply.aspx');
                            break;
                        case 40:
                            _this.toCheckPermit('confirmedit', '/page/Contract_ApplyInfo/OtherBusinessApply.aspx');

                            break;
                        default:
                            _this.toCheckPermit('confirm', '#');
                            break;
                    }

                    break;
                //作废编号                
                case "CancelCode":
                    if (_this.grid.getCurrentRecord().bArchivement) {
                        alert('该记录已生成业绩，不能作废编号！');
                        return;
                    }
                    this.loadInfo();
                    this.loadRemark();
                    this.cancelCodeRemark();
                    break;
                //业绩调整                
                case "AdjCommision":
                    var lockStatus = _this.grid.getCurrentRecord().LockStatus;
                    if (lockStatus & 8) {//1000(8)标识业绩调整是否封帐
                        alert('该记录未解封业绩调整，请联系管理员！');
                        return;
                    }
                    this.AdjCommision();
                    break;
                //诉讼申请                
                case "ApplyLitigation":
                    this.loadLitInfo();
                    this.ApplyLitigation();
                    break;
                //非诉申请                
                case "NotLitigation":
                    this.loadNotLitInfo();
                    this.NotLitigation();
                    break;
                //查看                
                case 'aView':

                    if (!_this.currentId) {
                        alert('请先选择一条成交记录！');
                        return;
                    }
                    switch (_this.grid.getCurrentRecord().BusinessType) {
                        case 10:
                        case 20:
                            _this.toCheckPermit('confirmview', '/page/Contract_ApplyInfo/MainBusinessApply.aspx');
                            break;
                        case 30:
                            _this.toCheckPermit('confirmview', '/page/Contract_ApplyInfo/LooseBusinessApply.aspx');
                            break;
                        case 40:
                            _this.toCheckPermit('confirmview', '/page/Contract_ApplyInfo/OtherBusinessApply.aspx');

                            break;
                        default:
                            _this.toCheckPermit('confirm', '#');
                            break;
                    }

                    break;
                //特殊折佣         
                case 'Discount':
                    if (!_this.currentId) {
                        alert('请先选择一条成交记录！');
                        return;
                    }
                    this.Discount();
                    break;
                case 'Relative':
                    if (!_this.currentId) {
                        alert('请先选择一条成交记录！');
                        return;
                    }
                    this.Relative();
                    break;
                default:
                    alert("功能未开通");
                    break;
            }
        },
        //调整率
        Relative: function() {
            var _this = this;
            if (!this.RelativeForm) {
                this.RelativeForm = new Chenxin.UI.Relative({
                    scope: this,
                    title: '调整率',
                    afterGetFormJson: function(json) {
                        _this.RelativeForm.additionalParam.modelid = _this.currentId;
                        _this.RelativeForm.additionalParam.DiscountRate = json.DiscountRate;
                    }
                });
            }
            var curData = {};
            Chenxin.apply(curData, this.grid.getCurrentRecord());
            if (this.RelativeForm.show()) {
                $("#div1").show();
                $("#div2").hide();
                this.RelativeForm.fitData(curData);
                this.RelativeForm.grid.reload({modelid: _this.currentId}, 0);
            }
        },
        //特殊折佣
        Discount: function() {
            var _this = this;
            if (!this.DiscountForm) {
                this.DiscountForm = new Chenxin.UI.Discount({
                    scope: this,
                    title: '特殊折让',
                    afterGetFormJson: function(json) {
                        delete json.HouseAddress;
                        delete json.ContractCode;
                    },
                    saveSucc: function() {
                        _this.grid.reload();
                    }
                });
            }
            var curData = {};
            Chenxin.apply(curData, this.grid.getCurrentRecord());
            if (this.DiscountForm.show()) {
                this.DiscountForm.fitData(curData);
            }
        },
        //删除成交编号备注
        cancelCodeRemark: function() {
            var _this = this;
            if (!this.CancelCodeRemarkForm) {
                this.CancelCodeRemarkForm = new Chenxin.UI.CancelCodeRemarkForm({
                    scope: this,
                    title: '删除成交编号备注',
                    url: "/service/logic/ShowRemarkInfo.ashx",
                    data: { op: 'searchRemark', ContractId: this.currentId },
                    afterGetFormJson: function(json) {
                        delete json.HouseAddress;
                        delete json.ContractCode;
                        json.Status = 30;
                    },
                    saveSucc: function() {
                        _this.grid.reload();
                    }
                });
            }
            if (this.CancelCodeRemarkForm.show()) {
                var _data = this.currentInfo;
                var _remark = this.currentRemark;
                this.CancelCodeRemarkForm.fitData(_data);
                this.CancelCodeRemarkForm.grid.clear();
                this.CancelCodeRemarkForm.grid.render(_remark);
            }
        },
        //取消业绩
        CancelFeat: function() {
            if (this.grid.getCurrentRecord().bArchivement == false) {
                alert('该记录未生成业绩，不能取消！');
                return;
            }
            this.del('cancelarchivement', '是否取消业绩？');
        },
        //生成业绩
        ProduceFeat: function() {
            if (!this.currentId) {
                alert('请选择一条成交记录！');
                return;
            }
            if (this.grid.getCurrentRecord().bArchivement) {
                alert('该记录已生成业绩，不能再次生成！');
                return;
            }
            if (!this.ProduceFeatForm) {
                this.ProduceFeatForm = new Chenxin.UI.ProduceFeatForm({
                    scope: this,
                    title: '生成业绩',
                    op: 'creatarchivement',
                    afterGetFormJson: function(json) {
                        this.ProduceFeatForm.additionalParam.modelid = _this.currentId;
                        this.ProduceFeatForm.additionalParam.ArchivementDate = json.ArchivementDate;
                    },
                    saveSucc: function() {
                        _this.grid.reload();
                    }
                });
            }
            if (this.ProduceFeatForm.show(this.ProduceFeatForm.op, { modelid: _this.currentId })) {
                Chenxin.Fn.getModel(_this.currentId, this.actionUrl, function(data) {
                    this.fitData(data.mod);

                    if (data.selectAllDate) {
                        var date = new Date();
                        this.minDate = (date.getFullYear() - 100) + '-' + (date.getMonth() + 1) + '-01';
                    }

                    $('#' + this.id + '_showpoint').html(data.point);
                }, this.ProduceFeatForm, 'getarchivement');
            }
        },
        //收付开单
        addBillPayment: function() {
            if (this.billPayFrm == undefined) {
                this.billPayFrm = new Chenxin.UI.BillPayFrm({
                    scope: this,
                    defBillDepart: this.grid.getCurrentRecord().VenderDepartId,
                    beforeFitData: function(json) {
                        if (json != "{}") {
                            json.CustomerName = json.VenderName;
                            json.BillDepartId = json.VenderDepartId;
                        }
                    },
                    afterGetFormJson: function(json) {
                        delete json.HouseAddress;
                        delete json.BargainPrice;
                        delete json.BargainCompanyName;
                        delete json.VenderName;
                        delete json.VenderDepartName;
                        delete json.BuyerName;
                        delete json.BuyerDepartName;
                        delete json.VRealCommisionFinal;
                        delete json.BRealCommisionFinal;


                        var CurData = this.grid.getCurrentRecord();
                        json.ContractId = CurData.ContractId;
                        json.ContractCityId = CurData.ContractCityId;
                        json.ContractCity = CurData.ContractCityName;
                        json.ContractCompanyId = CurData.ContractCompanyId;
                        json.ContractCompany = CurData.ContractCompanyName;
                        json.OrderPlace = CurData.ContractDepartmentName;
                        json.BillCompanyId = CurData.ContractCompanyId;
                        json.BillCompany = CurData.ContractCompanyName;
                        json.BillCityId = CurData.ContractCityId;
                        json.BillCity = CurData.ContractCityName;
                        //                    if( this.billPayFrm.comboList[0].getValue() != "" ){ 
                        //                        json.BillCompanyId = this.billPayFrm.comboList[0].getCurrentV("companyid");
                        //                        json.BillCompany = this.billPayFrm.comboList[0].getCurrentV("companyname");
                        //                    }
                    }
                });
            }
            var billData = {};
            var currentRecord = this.grid.getCurrentRecord();
            Chenxin.apply(billData, currentRecord);

            billData.BillDepartId = currentRecord.VenderDepartId;

            if (this.billPayFrm.show(this.billPayFrm.op)) {
                this.billPayFrm.fitData(billData);
                this.billPayFrm.findByName('InOrOut').eq(0).click();

                $("#paybank_tr").hide();
                $("#paybank1_tr").hide();
                this.billPayFrm.findByName('PayBankName').unFormValidator(true);
                this.billPayFrm.findByName('PayBankNo').unFormValidator(true);
                this.billPayFrm.findByName('PayBankType').required = false;
                /* 
                this.billPayFrm.reset();
                $("#divIn").css("display", "inline");
                $("#divOut").css("display", "none");
                $("#divIn").find("input[name='FundName']").eq(0).attr("checked", true);
                $("#sMsg").text("");
                $("#hidCanBill").text("0");
                this.billPayFrm.setTipMsg($("input[name='InOrOut']:checked").val(), $("input[name='FundName']:checked").val());
                this.billPayFrm.fitData(billData); */
            }
        },
        //应收登记
        RegIncome: function() {
            var objPg = this;
            if (!this.currentId) {
                alert('请选择一条成交记录！');
                return;
            }
            if (this.RegIncomeFrm == undefined) {
                this.RegIncomeFrm = new Chenxin.UI.RegIncomeForm({
                    scope: this,
                    beforeFitData: function(json) {
                        if (json != "{}") {
                            json.IncomeType = "代收房款";
                        }
                    },
                    afterGetFormJson: function(json) {
                        if (json != "{}") {
                            delete json.HouseAddress;
                            delete json.ContractCode;
                            delete json.BargainPrice;
                            delete json.VenderName;
                            delete json.BuyerName;
                            json.ContractId = objPg.currentId;
                            if (this.RegIncomeFrm.comboList[0].getValue() == "代收房款") {
                                json.CanGetSaleMoney = json.RegIncomeMoney;
                            } else {
                                json.CanGetTax = json.RegIncomeMoney;
                            }
                            delete json.IncomeType;
                            delete json.RegIncomeMoney;
                            this.RegIncomeFrm.additionalParam.IncomeType = this.RegIncomeFrm.comboList[0].getValue();
                        }
                    }
                });
            }
            var curData = {};
            this.RegIncomeFrm.reset();
            Chenxin.apply(curData, this.grid.getCurrentRecord());
            if (this.RegIncomeFrm.show()) {
                this.RegIncomeFrm.fitData(curData);
            }
        },
        //个案补证
        getLackItemsInfo: function() {
            var objPg = this;
            var json;
            if (this.addCertFrm == undefined) {
                this.addCertFrm = new Chenxin.UI.AddCertificatesFrm({
                    scope: this,
                    afterGetFormJson: function(json) {
                        if (json.IntentionCode) {
                            this.addCertFrm.additionalParam.IntentionCode = json.IntentionCode;
                        }
                        this.addCertFrm.additionalParam.ContractCode = json.ContractCode;
                        delete json.HouseAddress;
                        delete json.IntentionCode;
                        delete json.ContractCode;
                        json.ContractId = this.grid.getCurrentRecord().ContractId;
                    }
                });
            }
            if (objPg.addCertFrm.show(objPg.addCertFrm.op, { CityId: this.grid.getCurrentRecord().BargainCityId, CompanyId: this.grid.getCurrentRecord().BargainCompanyId }) == true) {
                Chenxin.ajax({
                    type: "get",
                    dataType: "json",
                    url: this.actionUrl,
                    data: { op: 'getlackitemsinfo', ContractId: this.currentId },
                    onSuccess: function(data) {
                        var Contractdata = eval("({" + data + "})");
                        if (Contractdata.rows.length > 0) {
                            Contractdata = Contractdata.rows[0];
                        } else {
                            Contractdata = {};
                        }
                        Contractdata.ContractCode = objPg.grid.getCurrentRecord().ContractCode;
                        Contractdata.HouseAddress = objPg.grid.getCurrentRecord().HouseAddress;
                        objPg.addCertFrm.reset();
                        objPg.addCertFrm.fitData(Contractdata);
                    }
                });
            }
        },
        UploadFile: function() {
            if (!this.currentId) {
                alert('请选择一条成交记录！');
                return;
            }
            if (this.uploadFileFrm == undefined) {
                this.uploadFileFrm = new Chenxin.UI.UploadFileFrm({
                    scope: this,
                    afterGetFormJson: function(json) {
                        if (this.uploadFileFrm.filename != undefined) {
                            json.RelationId = this.grid.getCurrentRecord().ContractId;
                            json.FileName = this.uploadFileFrm.filename;
                            json.Path = this.uploadFileFrm.savename;
                        }
                    }
                });
            }
            this.uploadFileFrm.reset();
            this.uploadFileFrm.show();
        },
        edit: function() {
            var _this = this;
            if (!_this.currentId) {
                alert('请先选择一条报备记录！');
                return;
            }
        },
        toCheckPermit: function(op, url) {
            var _this = this;
            if (!_this.currentId) {
                alert('请先选择一条报备记录！');
                return;
            }
            Chenxin.Fn.checkPermit(_this.actionUrl, op, function(data, msg) {
                if (data.permit != undefined) {
                    _this.permit = data.permit;
                    _this.msg = msg;
                }
            }, this, { modelid: _this.currentId });
            if (_this.permit) {
                window.open(url + "?RecordId=" + _this.currentId + "&op=" + op);
                // window.location.href = "" + url + "?RecordId=" + _this.currentId + "&wfrom=1";
                //                if (op=='confirmview')
                //					window.open(url + "?RecordId=" + _this.currentId + "&op=" + op);
                //				else
                //					window.location.href = "" + url + "?RecordId=" + _this.currentId + "&op=" + op;
            } else {
                alert(_this.msg);
            }
        },
        AdjCommision: function() {
            if (!this.currentId) {
                alert('请先选择一条报备记录！');
                return;
            }
            if (this.AdjCommFrm == undefined) {
                this.AdjCommFrm = new Chenxin.UI.AdjCommisionForm({
                    scope: this,
                    afterGetFormJson: function(json) {
                        var ContractData = this.grid.getCurrentRecord();
                        delete json.AppDepart;
                        delete json.HouseAddress;
                        delete json.VenderName;
                        delete json.BuyerName;
                        delete json.PayedMoney;

                        json.ContractId = ContractData.ContractId;
                        json.ContractCityId = ContractData.ContractCityId;
                        json.ContractCity = ContractData.ContractCityName;
                        json.ContractCompanyId = ContractData.ContractCompanyId;
                        json.ContractCompany = ContractData.ContractCompanyName;
                    },
                    saveSucc: function() {
                        this.reloadGrid();
                    }
                });
            }
            this.AdjCommFrm.reset();
            if (this.AdjCommFrm.show()) {
                this.AdjCommFrm.fitData(this.grid.getCurrentRecord());
                this.AdjCommFrm.setMoney("10");
            }
        },
        /**
        *诉讼申请
        */
        ApplyLitigation: function() {
            var _this = this;
            if (!this.currentId) {
                alert('请先选择一条报备记录！');
                return;
            }
            if (!this.ApplyLitigationForm) {
                this.ApplyLitigationForm = new Chenxin.UI.ApplyLitigationForm({
                    scope: _this,
                    alwaysCheckPermit: true,
                    title: '诉讼申请',
                    op: 'applylitigation',
                    afterGetFormJson: function(json) {
                    },
                    saveSucc: function() {
                        _this.grid.reload();
                    }
                });
            }
            if (this.ApplyLitigationForm.show()) {
                var _data = this.currentLitInfo;
                this.ApplyLitigationForm.reset();
                _data.ContractId = this.grid.getCurrentRecord().ContractId;
                _data.ContractCode = this.grid.getCurrentRecord().ContractCode;
                _data.HouseAddress = this.grid.getCurrentRecord().HouseAddress;
                this.ApplyLitigationForm.fitData(_data);
            }
        },
        /**
        *非诉申请
        */
        NotLitigation: function() {
            var _this = this;
            if (!this.currentId) {
                alert('请先选择一条报备记录！');
                return;
            }
            if (!this.NotLitigationForm) {
                this.NotLitigationForm = new Chenxin.UI.NotLitigationForm({
                    scope: _this,
                    alwaysCheckPermit: true,
                    title: '非诉申请',
                    op: 'nolitigation',
                    afterGetFormJson: function(json) {
                    },
                    saveSucc: function() {
                        _this.grid.reload();
                    }
                });
            }
            if (this.NotLitigationForm.show()) {
                var _data = this.currentNotLitInfo;
                this.NotLitigationForm.reset();
                _data.ContractId = this.grid.getCurrentRecord().ContractId;
                _data.ContractCode = this.grid.getCurrentRecord().ContractCode;
                _data.HouseAddress = this.grid.getCurrentRecord().HouseAddress;
                this.NotLitigationForm.fitData(_data);
            }
        },
        createSearch: function() {
            return new Chenxin.UI.ApplyInfoSearch({
                scope: this
            });
        },
        customerInit: function() {
            var unLockMenu = new Chenxin.UI.Menu({
                id: 'x_btn_unlock',
                scope: this,
                items: [{
                    text: '解封全部',
                    handler: function() {
                        this.del('openall', '是否解封该记录？', '', { flg: 0 });
                    }
                }, {
                    text: '解封资料',
                    handler: function() {
                        this.del('opendata', '是否解封该记录资料？', '', { flg: 10 });
                    }
                }, {
                    text: '解封佣金',
                    handler: function() {
                        this.del('opencommission', '是否解封该记录佣金？', '', { flg: 20 });
                    }
                }, {
                    text: '解封点数',
                    handler: function() {
                        this.del('openpoint', '是否解封该记录点数？', '', { flg: 30 });
                    }
                }, {
                    text: '成交瑕疵',
                    handler: function() {
                        this.del('openflaw', '是否解封该记录成交瑕疵？', '', { flg: 40 });
                    }
}]
                });
            },
            initComponent: function() {
                Chenxin.UI.ApplyInfoManage.superclass.initComponent.call(this);
                this.searchGrid();
            }
        });


        var columns = {
            /**主营业务模式表头-买卖*/
            mainSaleHead: {
                logFlg: {
                    width: 40,
                    items: {
                        LockStatus: {
                            canExport: false,
                            width: 40,
                            head: '封帐',
                            renderer: function(val, field, row) {
                                if (val != 255) {
                                    return '<input type="checkbox" disabled="disabled" />';
                                }
                                return '<input type="checkbox" disabled="disabled" checked="checked"/>'
                            }
                        },
                        bArchivement: {
                            canExport: false,
                            width: 40,
                            head: '业绩',
                            renderer: function(val, field, row) {
                                if (val) {
                                    return '<input type="checkbox" disabled="disabled" checked="checked"/>';
                                }
                                return '<input type="checkbox" disabled="disabled"/>'
                            }
                        }
                    }
                },
                ContractUserName: {
                    width: 60,
                    head: '签约人员'
                },
                ContractCode: {
                    width: 120,
                    head: '成交编号'
                },
                ContractDate: {
                    width: 80,
                    head: '成交日期'
                },
                Status: {
                    width: 60,
                    head: '状态',
                    renderer: function(val, field, row) {
                        if (val == 1) {
                            return '正常';
                        }
                        else
                            return '作废';
                    }
                },
                DepartName: {
                    width: 100,
                    items: {
                        VenderDepartName: {
                            width: 100,
                            head: '房源门店'
                        },
                        BuyerDepartName: {
                            width: 100,
                            head: '客源门店'
                        }
                    }
                },
                Name: {
                    width: 80,
                    items: {
                        VenderName: {
                            width: 80,
                            head: '上家姓名'
                        },
                        BuyerName: {
                            width: 80,
                            head: '下家姓名'
                        }
                    }
                },
                Tel: {
                    width: 180,
                    canExport: false,
                    items: {
                        VenderPhone: {
                            canExport: false,
                            textModel: true,
                            width: 180,
                            head: '上家电话',
                            renderer: function(val, field, row) {
                                if (val.length < 1) {
                                    if (row.VenderMobile == null || (row.VenderMobile + '').length < 1)
                                        return '-';
                                    else
                                        return row.VenderMobile;
                                }
                                else {
                                    if (row.VenderMobile == null || (row.VenderMobile + '').length < 1)
                                        return val;
                                    else
                                        return val + '/' + row.VenderMobile;
                                }
                            }
                        },
                        BuyerPhone: {
                            canExport: false,
                            textModel: true,
                            width: 180,
                            head: '下家电话',
                            renderer: function(val, field, row) {
                                if (val.length < 1) {
                                    if (row.BuyerMobile == null || (row.BuyerMobile + '').length < 1)
                                        return '-';
                                    else
                                        return row.BuyerMobile;
                                }
                                else {
                                    if (row.BuyerMobile == null || (row.BuyerMobile + '').length < 1)
                                        return val;
                                    else
                                        return val + '/' + row.BuyerMobile;
                                };
                            }
                        }
                    }
                },

                Region: {
                    head: '区域',
                    width: 60
                },
                HouseAddress: {
                    head: '房屋地址',
                    width: 250
                },
                Area: {
                    head: '面积',
                    width: 60
                },
                BargainPrice: {
                    head: '合同标的',
                    width: 80
                },
                Commision1: {
                    width: 80,
                    items: {
                        VStanCommision: {
                            width: 80,
                            head: '上家标准佣收'
                        },
                        BStanCommision: {
                            width: 80,
                            head: '下家标准佣金'
                        }
                    }
                },
                Commision2: {
                    width: 80,
                    items: {
                        VRealCommisionFinal: {
                            width: 80,
                            head: '上家确认佣收'
                        },
                        BRealCommisionFinal: {
                            width: 80,
                            head: '下家确认佣收'
                        }
                    }
                },
                CommisionGeted: {
                    width: 80,
                    items: {
                        VCommisionGeted: {
                            width: 80,
                            head: '上家实收'
                        },
                        BCommisionGeted: {
                            width: 80,
                            head: '下家实收'
                        }
                    }
                },
                CommisionGetedPayed: {
                    width: 80,
                    items: {
                        VNotGeted: {
                            width: 80,
                            head: '上家未收'
                        },
                        BNotGeted: {
                            width: 80,
                            head: '下家未收'
                        }
                    }
                },
                BCommision: {
                    width: 80,
                    items: {
                        VCommisionFinal: {
                            width: 80,
                            head: '上家折佣'
                        },
                        BCommisionFinal: {
                            width: 80,
                            head: '下家折佣'
                        }
                    }
                },
                Consulting: {
                    width: 80,
                    items: {
                        VConsultingFinal: {
                            width: 80,
                            head: '上家咨询费'
                        },
                        BConsultingFinal: {
                            width: 80,
                            head: '下家咨询费'
                        }
                    }
                },
                ConsultingPayed: {
                    width: 120,
                    items: {
                        VConsultingPayed: {
                            width: 120,
                            head: '上家咨询费实付'
                        },
                        BConsultingPayed: {
                            width: 120,
                            head: '下家咨询费实付'
                        }
                    }
                },
                Depart: {
                    width: 140,
                    items: {
                        V_Departs: {
                            width: 140,
                            head: '上家门店'
                        },
                        B_Departs: {
                            width: 140,
                            head: '下家门店'
                        }
                    }
                },
                Employee: {
                    width: 80,
                    items: {
                        V_Users: {
                            width: 80,
                            head: '上家经纪人'
                        },
                        B_Users: {
                            width: 80,
                            head: '下家经纪人'
                        }
                    }
                },
                Point: {
                    width: 80,
                    items: {
                        V_Points: {
                            width: 80,
                            head: '上家点数'
                        },
                        B_Points: {
                            width: 80,
                            head: '下家点数'
                        }
                    }
                },
				FixDiscountFinal: {
                    width: 80,
                    head: '固定扣除'
                },
                ArchivementDate: {
                    width: 80,
                    head: '业绩归属时间'
                },
                LastCreateArchDate: {
                    width: 80,
                    head: '业绩确认时间',
                    renderer: function(val) {
                        return val.substr(0, 10);
                    }
                },
                CreateArchEmp: {
                    width: 80,
                    head: '业绩确认人'
                },
                BargainType: {
                    width: 50,
                    head: '签约方式'
                },
                CustomerSource: {
                    head: '客户来源',
                    width: 60
                },
                ConfirmEmplyee: {
                    width: 80,
                    head: '编号建档人'
                },
                LackDocument: {
                    width: 400,
                    head: '补证资料'
                },
                Memo: {
                    width: 400,
                    head: '备注'
                }
            },
            mainRentHead: {
                logFlg: {
                    width: 40,
                    items: {
                        LockStatus: {
                            canExport: false,
                            width: 40,
                            head: '封帐',
                            renderer: function(val, field, row) {
                                if (val != 255) {
                                    return '<input type="checkbox" disabled="disabled" />';
                                }
                                return '<input type="checkbox" disabled="disabled" checked="checked"/>'
                            }
                        },
                        bArchivement: {
                            canExport: false,
                            width: 40,
                            head: '业绩',
                            renderer: function(val, field, row) {
                                if (val) {
                                    return '<input type="checkbox" disabled="disabled" checked="checked"/>';
                                }
                                return '<input type="checkbox" disabled="disabled"/>'
                            }
                        }
                    }
                },
                ContractUserName: {
                    width: 60,
                    head: '签约人员'
                },
                ContractCode: {
                    width: 120,
                    head: '成交编号'
                },
                ContractDate: {
                    width: 80,
                    head: '成交日期'
                },
                Status: {
                    width: 60,
                    head: '状态',
                    renderer: function(val, field, row) {
                        if (val == 1) {
                            return '正常';
                        }
                        else
                            return '作废';
                    }
                },
                DepartName: {
                    width: 80,
                    items: {
                        VenderDepartName: {
                            width: 80,
                            head: '房源门店'
                        },
                        BuyerDepartName: {
                            width: 80,
                            head: '客源门店'
                        }
                    }
                },
                Name: {
                    width: 80,
                    items: {
                        VenderName: {
                            width: 80,
                            head: '上家姓名'
                        },
                        BuyerName: {
                            width: 80,
                            head: '下家姓名'
                        }
                    }
                },
                Tel: {
                    width: 180,
                    canExport: false,
                    items: {
                        VenderPhone: {
                            canExport: false,
                            textModel: true,
                            width: 180,
                            head: '上家电话',
                            renderer: function(val, field, row) {
                                if (val.length < 1) {
                                    if (row.VenderMobile == null || (row.VenderMobile + '').length < 1)
                                        return '-';
                                    else
                                        return row.VenderMobile;
                                }
                                else {
                                    if (row.VenderMobile == null || (row.VenderMobile + '').length < 1)
                                        return val;
                                    else
                                        return val + '/' + row.VenderMobile;
                                }
                            }
                        },
                        BuyerPhone: {
                            canExport: false,
                            textModel: true,
                            width: 180,
                            head: '下家电话',
                            renderer: function(val, field, row) {
                                if (val.length < 1) {
                                    if (row.BuyerMobile == null || (row.BuyerMobile + '').length < 1)
                                        return '-';
                                    else
                                        return row.BuyerMobile;
                                }
                                else {
                                    if (row.BuyerMobile == null || (row.BuyerMobile + '').length < 1)
                                        return val;
                                    else
                                        return val + '/' + row.BuyerMobile;
                                };
                            }
                        }
                    }
                },
                Region: {
                    head: '区域',
                    width: 60
                },
                HouseAddress: {
                    head: '房屋地址',
                    width: 250
                },
                Area: {
                    head: '面积',
                    width: 60
                },
                BargainPrice: {
                    head: '合同标的',
                    width: 80
                },
                Commision1: {
                    width: 80,
                    items: {
                        VStanCommision: {
                            width: 80,
                            head: '上家标准佣收'
                        },
                        BStanCommision: {
                            width: 80,
                            head: '下家标准佣金'
                        }
                    }
                },
                Commision2: {
                    width: 80,
                    items: {
                        VRealCommisionFinal: {
                            width: 80,
                            head: '上家确认佣收'
                        },
                        BRealCommisionFinal: {
                            width: 80,
                            head: '下家确认佣收'
                        }
                    }
                },
                CommisionGeted: {
                    width: 80,
                    items: {
                        VCommisionGeted: {
                            width: 80,
                            head: '上家实收'
                        },
                        BCommisionGeted: {
                            width: 80,
                            head: '下家实收'
                        }
                    }
                },
                CommisionGetedPayed: {
                    width: 80,
                    items: {
                        VNotGeted: {
                            width: 80,
                            head: '上家未收'
                        },
                        BNotGeted: {
                            width: 80,
                            head: '下家未收'
                        }
                    }
                },
                BCommision: {
                    width: 80,
                    items: {
                        VCommisionFinal: {
                            width: 80,
                            head: '上家折佣'
                        },
                        BCommisionFinal: {
                            width: 80,
                            head: '下家折佣'
                        }
                    }
                },
                Consulting: {
                    width: 80,
                    items: {
                        VConsultingFinal: {
                            width: 80,
                            head: '上家咨询费'
                        },
                        BConsultingFinal: {
                            width: 80,
                            head: '下家咨询费'
                        }
                    }
                },
                ConsultingPayed: {
                    width: 120,
                    items: {
                        VConsultingPayed: {
                            width: 120,
                            head: '上家咨询费实付'
                        },
                        BConsultingPayed: {
                            width: 120,
                            head: '下家咨询费实付'
                        }
                    }
                },
                Depart: {
                    width: 140,
                    items: {
                        V_Departs: {
                            width: 140,
                            head: '上家门店'
                        },
                        B_Departs: {
                            width: 140,
                            head: '下家门店'
                        }
                    }
                },
                Employee: {
                    width: 80,
                    items: {
                        V_Users: {
                            width: 80,
                            head: '上家经纪人'
                        },
                        B_Users: {
                            width: 80,
                            head: '下家经纪人'
                        }
                    }
                },
                Point: {
                    width: 80,
                    items: {
                        V_Points: {
                            width: 80,
                            head: '上家点数'
                        },
                        B_Points: {
                            width: 80,
                            head: '下家点数'
                        }
                    }
                },
                ArchivementDate: {
                    width: 80,
                    head: '业绩归属时间'
                },
                LastCreateArchDate: {
                    width: 80,
                    head: '业绩确认时间',
                    renderer: function(val) {
                        return val.substr(0, 10);
                    }
                },
                CreateArchEmp: {
                    width: 80,
                    head: '业绩确认人'
                },
                BargainType: {
                    width: 50,
                    head: '签约方式'
                },
                CustomerSource: {
                    head: '客户来源',
                    width: 60
                },
                ConfirmEmplyee: {
                    width: 80,
                    head: '编号建档人'
                },
                LackDocument: {
                    width: 400,
                    head: '补证资料'
                },
                Memo: {
                    width: 400,
                    head: '备注'
                }
            },
            subHead: {
                logFlg: {
                    width: 40,
                    items: {
                        LockStatus: {
                            canExport: false,
                            width: 40,
                            head: '封帐',
                            renderer: function(val, field, row) {
                                if (val != 255) {
                                    return '<input type="checkbox" disabled="disabled" />';
                                }
                                return '<input type="checkbox" disabled="disabled" checked="checked"/>'
                            }
                        },
                        bArchivement: {
                            canExport: false,
                            width: 40,
                            head: '业绩',
                            renderer: function(val, field, row) {
                                if (val) {
                                    return '<input type="checkbox" disabled="disabled" checked="checked"/>';
                                }
                                return '<input type="checkbox" disabled="disabled"/>'
                            }
                        }
                    }
                },
                ContractUserName: {
                    width: 60,
                    head: '签约人员'
                },
                ContractCode: {
                    width: 120,
                    head: '成交编号'
                },
                ContractDate: {
                    width: 80,
                    head: '成交日期'
                },
                Status: {
                    width: 60,
                    head: '状态',
                    renderer: function(val, field, row) {
                        if (val == 1) {
                            return '正常';
                        }
                        else
                            return '作废';
                    }
                },
                BuyerDepartName: {
                    width: 80,
                    head: '客源门店'
                },
                Name: {
                    width: 80,
                    items: {
                        VenderName: {
                            width: 80,
                            head: '上家姓名'
                        },
                        BuyerName: {
                            width: 80,
                            head: '下家姓名'
                        }
                    }
                },
                Tel: {
                    width: 180,
                    canExport: false,
                    textModel: true,
                    items: {
                        VenderPhone: {
                            canExport: false,
                            width: 180,
                            head: '上家电话',
                            renderer: function(val, field, row) {
                                if (val.length < 1) {
                                    if (row.VenderMobile == null || (row.VenderMobile + '').length < 1)
                                        return '-';
                                    else
                                        return row.VenderMobile;
                                }
                                else {
                                    if (row.VenderMobile == null || (row.VenderMobile + '').length < 1)
                                        return val;
                                    else
                                        return val + '/' + row.VenderMobile;
                                }
                            }
                        },
                        BuyerPhone: {
                            canExport: false,
                            textModel: true,
                            width: 180,
                            head: '下家电话',
                            renderer: function(val, field, row) {
                                if (val.length < 1) {
                                    if (row.BuyerMobile == null || (row.BuyerMobile + '').length < 1)
                                        return '-';
                                    else
                                        return row.BuyerMobile;
                                }
                                else {
                                    if (row.BuyerMobile == null || (row.BuyerMobile + '').length < 1)
                                        return val;
                                    else
                                        return val + '/' + row.BuyerMobile;
                                };
                            }
                        }
                    }
                },
                Region: {
                    head: '区域',
                    width: 60
                },
                HouseAddress: {
                    head: '房屋地址',
                    width: 250
                },
                Area: {
                    head: '面积',
                    width: 60
                },
                BargainPrice: {
                    head: '合同标的',
                    width: 80
                },
                Commision2: {
                    width: 80,
                    items: {
                        VRealCommisionFinal: {
                            width: 80,
                            head: '上家确认佣收'
                        },
                        BRealCommisionFinal: {
                            width: 80,
                            head: '下家确认佣收'
                        }
                    }
                },
                CommisionGeted: {
                    width: 80,
                    items: {
                        VCommisionGeted: {
                            width: 80,
                            head: '上家实收'
                        },
                        BCommisionGeted: {
                            width: 80,
                            head: '下家实收'
                        }
                    }
                },
                CommisionGetedPayed: {
                    width: 80,
                    items: {
                        VNotGeted: {
                            width: 80,
                            head: '上家未收'
                        },
                        BNotGeted: {
                            width: 80,
                            head: '下家未收'
                        }
                    }
                },
                BCommision: {
                    width: 80,
                    items: {
                        VCommisionFinal: {
                            width: 80,
                            head: '上家折佣'
                        },
                        BCommisionFinal: {
                            width: 80,
                            head: '下家折佣'
                        }
                    }
                },
                Consulting: {
                    width: 80,
                    items: {
                        VConsultingFinal: {
                            width: 80,
                            head: '上家咨询费'
                        },
                        BConsultingFinal: {
                            width: 80,
                            head: '下家咨询费'
                        }
                    }
                },
                ConsultingPayed: {
                    width: 120,
                    items: {
                        VConsultingPayed: {
                            width: 120,
                            head: '上家咨询费实付'
                        },
                        BConsultingPayed: {
                            width: 120,
                            head: '下家咨询费实付'
                        }
                    }
                },
                Departs: {
                    width: 140,
                    head: '业务门店'
                },
                Users: {
                    width: 80,
                    head: '业务人员'
                },
                Points: {
                    width: 80,
                    head: '点数'
                },

                ArchivementDate: {
                    width: 80,
                    head: '业绩归属时间'
                },
                LastCreateArchDate: {
                    width: 80,
                    head: '业绩确认时间',
                    renderer: function(val) {
                        return val.substr(0, 10);
                    }
                },
                CreateArchEmp: {
                    width: 80,
                    head: '业绩确认人'
                },
                CustomerSource: {
                    head: '客户来源',
                    width: 60
                },
                ConfirmEmplyee: {
                    width: 80,
                    head: '编号建档人'
                },
                Memo: {
                    width: 100,
                    head: '备注'
                }
            },
            otherHead: {
                logFlg: {
                    width: 40,
                    items: {
                        LockStatus: {
                            canExport: false,
                            width: 40,
                            head: '封帐',
                            renderer: function(val, field, row) {
                                if (val != 255) {
                                    return '<input type="checkbox" disabled="disabled" />';
                                }
                                return '<input type="checkbox" disabled="disabled" checked="checked"/>'
                            }
                        },
                        bArchivement: {
                            canExport: false,
                            width: 40,
                            head: '业绩',
                            renderer: function(val, field, row) {
                                if (val) {
                                    return '<input type="checkbox" disabled="disabled" checked="checked"/>';
                                }
                                return '<input type="checkbox" disabled="disabled"/>'
                            }
                        }
                    }
                },
                ContractUserName: {
                    width: 60,
                    head: '签约人员'
                },
                ContractCode: {
                    width: 120,
                    head: '成交编号'
                },
                ContractDate: {
                    width: 80,
                    head: '成交日期'
                },
                Status: {
                    width: 60,
                    head: '状态',
                    renderer: function(val, field, row) {
                        if (val == 1) {
                            return '正常';
                        }
                        else
                            return '作废';
                    }
                },
                BuyerDepartName: {
                    width: 80,
                    head: '客源门店'
                },
                Name: {
                    width: 80,
                    items: {
                        VenderName: {
                            width: 80,
                            head: '上家姓名'
                        },
                        BuyerName: {
                            width: 80,
                            head: '下家姓名'
                        }
                    }
                },
                Tel: {
                    width: 180,
                    canExport: false,
                    items: {
                        VenderPhone: {
                            canExport: false,
                            textModel: true,
                            width: 180,
                            head: '上家电话',
                            renderer: function(val, field, row) {
                                if (val.length < 1) {
                                    if (row.VenderMobile == null || (row.VenderMobile + '').length < 1)
                                        return '-';
                                    else
                                        return row.VenderMobile;
                                }
                                else {
                                    if (row.VenderMobile == null || (row.VenderMobile + '').length < 1)
                                        return val;
                                    else
                                        return val + '/' + row.VenderMobile;
                                }
                            }
                        },
                        BuyerPhone: {
                            canExport: false,
                            textModel: true,
                            width: 180,
                            head: '下家电话',
                            renderer: function(val, field, row) {
                                if (val.length < 1) {
                                    if (row.BuyerMobile == null || (row.BuyerMobile + '').length < 1)
                                        return '-';
                                    else
                                        return row.BuyerMobile;
                                }
                                else {
                                    if (row.BuyerMobile == null || (row.BuyerMobile + '').length < 1)
                                        return val;
                                    else
                                        return val + '/' + row.BuyerMobile;
                                };
                            }
                        }
                    }
                },

                BusinessDescribe: {
                    head: '业务描述',
                    width: 400
                },
                Commision2: {
                    width: 80,
                    items: {
                        VRealCommisionFinal: {
                            width: 80,
                            head: '上家确认佣收'
                        },
                        BRealCommisionFinal: {
                            width: 80,
                            head: '下家确认佣收'
                        }
                    }
                },
                CommisionGeted: {
                    width: 80,
                    items: {
                        VCommisionGeted: {
                            width: 80,
                            head: '上家实收'
                        },
                        BCommisionGeted: {
                            width: 80,
                            head: '下家实收'
                        }
                    }
                },
                CommisionGetedPayed: {
                    width: 80,
                    items: {
                        VNotGeted: {
                            width: 80,
                            head: '上家未收'
                        },
                        BNotGeted: {
                            width: 80,
                            head: '下家未收'
                        }
                    }
                },
                BCommision: {
                    width: 80,
                    items: {
                        VCommisionFinal: {
                            width: 80,
                            head: '上家折佣'
                        },
                        BCommisionFinal: {
                            width: 80,
                            head: '下家折佣'
                        }
                    }
                },
                Consulting: {
                    width: 80,
                    items: {
                        VConsultingFinal: {
                            width: 80,
                            head: '上家咨询费'
                        },
                        BConsultingFinal: {
                            width: 80,
                            head: '下家咨询费'
                        }
                    }
                },
                ConsultingPayed: {
                    width: 120,
                    items: {
                        VConsultingPayed: {
                            width: 120,
                            head: '上家咨询费实付'
                        },
                        BConsultingPayed: {
                            width: 120,
                            head: '下家咨询费实付'
                        }
                    }
                },
                Departs: {
                    width: 140,
                    head: '业务门店'
                },
                Users: {
                    width: 80,
                    head: '业务人员'
                },
                Points: {
                    width: 80,
                    head: '点数'
                },

                ArchivementDate: {
                    width: 80,
                    head: '业绩归属时间'
                },
                LastCreateArchDate: {
                    width: 80,
                    head: '业绩确认时间',
                    renderer: function(val) {
                        return val.substr(0, 10);
                    }
                },
                CreateArchEmp: {
                    width: 80,
                    head: '业绩确认人'
                },
                CustomerSource: {
                    head: '客户来源',
                    width: 60
                },
                ConfirmEmplyee: {
                    width: 80,
                    head: '编号建档人'
                },
                Memo: {
                    width: 100,
                    head: '备注'
                }
            }
        }

/**
*查询面板
*/
        Chenxin.UI.ApplyInfoSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
            id: 'applyinfo_search',
            initEvent: function() {
                var _this = this;
                //查询
                $('#btnSearch').click(function() {
                    _this.scope.searchGrid();
                });
                $('#txtKeyword').defText({
                    deftxt: '输入成交编号/房源地址/客户姓名'
                });

                var curdate = new Date();
                $('#starttime').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 1) + '-1');
                if (curdate.getMonth() + 1 == 12)
                    $('#eTime').val(curdate.getFullYear() + 1 + '-1-1');
                else
                    $('#eTime').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 2) + '-1');
            },
            createComboList: function() {
                //合同类型
                var status = new Chenxin.UI.Combo({
                    containerId: '#status',
                    tbxWidth: 60,
                    items: comboCommon.BargainStatus,
                    addPleaseSelected: false
                });

                var dayType = new Chenxin.UI.Combo({
                    containerId: '#timetype',
                    tbxWidth: 60,
                    items: comboCommon.TimeType,
                    addPleaseSelected: false
                });

                var region = new Chenxin.UI.ParameterCombo({
                    name: 'region',
                    containerId: '#region',
                    key: 'System.Region',
                    tbxWidth: 60,
                    inModelType: 'txt'
                });

                var rate = new Chenxin.UI.Combo({
                    name: 'rate',
                    containerId: '#rate',
                    tbxWidth: 60,
                    items: [{ val: '1', txt: '调整' }, { val: '-1', txt: '未调整'}]
                });

                var litigation = new Chenxin.UI.Combo({
                    name: 'litigation',
                    containerId: '#litigation',
                    tbxWidth: 60,
                    items: [{ val: '10', txt: '非诉' }, { val: '20', txt: '诉讼' }, { val: '-1', txt: '无诉讼'}]
                });

                var combl = new Chenxin.UI.StructComboList({
                    tbxWidth: 60,
                    cityAfterSelected: function(val) {
                        if (val == combl.city.defVal) {
                            region.clearItems();
                        } else {
                            region.param.cityid = val;
                            region.param.filter = 'bycity';
                            region.reload();
                        }
                    }
                });
                var structs = combl.comboList;
                structs.push(status);
                structs.push(region);
                structs.push(dayType);
                structs.push(rate);
                structs.push(litigation);
                return structs;
            },
            initComponent: function() {
                Chenxin.UI.ApplyInfoSearch.superclass.initComponent.call(this);
            }
        });

/*
**
*/
Chenxin.UI.BillPayFrm = Chenxin.extend(Chenxin.UI.FormCommon, {
    id: "jqmBillPay",
    renderTo: 'jqmBillPay',
    actionUrl: "/service/logic/ShowListBargain.ashx",
    title: "收付开单",
    op: "addbillpay",
    defBBtn: true,
    jqmWidth: 700,
    createForm: function() {
        return Chenxin.FormCommon.billPaymentForm(this.id);
        // return formCommon.BillPaymentForm();
    },
    saveSucc: function(data) {
        var _this = this;
        _this.CurModel = data.model;

        if (_this.CurModel.InOrOut == "1") {//收款单
            if (_this.printInForm == undefined) {
                _this.printInForm = new Chenxin.UI.PrintInBillForm({
                    scope: _this,
                    op: 'printview'
                });
            }

            if (_this.printInForm.show('reprintview') == false) return;
            _this.printInForm.reset();
            _this.printInForm.fitData(_this.CurModel);
        } else {//付款单
            if (_this.CurModel.FundName != "代付房款") {
                if (_this.printOutForm == undefined) {
                    _this.printOutForm = new Chenxin.UI.PrintOutBillForm({
                        scope: _this,
                        op: 'printview'
                    });
                };

                if (_this.printOutForm.show('reprintview') == false) return;
                _this.printOutForm.reset();
                _this.printOutForm.fitData(_this.CurModel);
            } else {
                if (_this.printHouseForm == undefined) {
                    _this.printHouseForm = new Chenxin.UI.PrintHouseBillForm({
                        scope: _this,
                        op: 'printview'
                    });
                };

                if (_this.printHouseForm.show('printview') == false) return;
                _this.printHouseForm.reset();
                _this.printHouseForm.fitData(_this.CurModel);
            }
        }
        //        if (_this.printInForm == undefined) {
        //            _this.printInForm = new Chenxin.UI.PrintInBillForm({
        //                scope: this
        //            })
        //        };

        //        _this.printInForm.show(_this.printInForm.op);
    },
    setTipMsg: function(InOrOut, FundName) {
        var strShow = "";
        var strEnd = "";
        Chenxin.ajax({
            type: "get",
            dataType: "json",
            url: this.actionUrl,
            data: { op: 'getremain', ContractId: this.scope.grid.getCurrentRecord().ContractId, InOrOut: InOrOut, FundName: FundName },
            onSuccess: function(data) {
                if (data.CanBill < 0) {
                    data.CanBill = 0;
                    strEnd = data.CanBill + "元 ！！！应开付款单！！！";
                } else {
                    strEnd = data.CanBill + "元";
                }
                strShow = "款项总额：" + data.Total + "元 | 已收付金额：" + data.Payed + " 元 | 已开金额：" + data.Billed + "元 | 可开金额：" + strEnd;
                $("#hidCanBill").text(data.CanBill);
                $("#sMsg").text(strShow);
                $("input[name='BillMoney']").val(data.CanBill);
                $("#hidCanBill").text(data.CanBill);
            }
        });
    },
    initFormValidator: function() {
        //开单金额
        $("#txtBillMoney").formValidator({
            validatorgroup: this.id,
            onshow: "请输入开单金额！",
            onfocus: "本次开单金额不能大于可开金额",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "开单金额不能为空！"
            },
            onerror: "开单金额不能为空！"
        }).functionValidator({
            fun: function() {
                var CanBill = parseFloat($("#hidCanBill").text());
                if (CanBill < 0.001) {
                    return "本次可开金额为零,不可继续开单";
                } else {
                    var Bill = $("#txtBillMoney").val();
                    if (Bill.isNum()) {
                        if (parseFloat(Bill) > CanBill) {
                            return "本次开单金额不能大于可开金额";
                        } else {
                            return true;
                        }
                    } else {
                        return "金额格式不正确";
                    }
                }
            },
            onerror: "本次开单金额不能大于可开金额"
        });
        //开单日期
        $("#txtBillDate").formValidator({
            validatorgroup: this.id,
            onshow: "请输入",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "不能为空"
            },
            onerror: "不能为空"
        });
        //客户姓名
        $("#txtCustomerName").formValidator({
            validatorgroup: this.id,
            onshow: "请输入",
            onfocus: "不能为空",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "不能为空"
            },
            onerror: "不能为空"
        });
        //划账银行
        $("#PayBankName").formValidator({
            validatorgroup: this.id,
            onshow: "请输入",
            onfocus: "不能为空",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "不能为空"
            },
            onerror: "不能为空"
        });
        //划账账号
        $("#PayBankNo").formValidator({
            validatorgroup: this.id,
            onshow: "请输入",
            onfocus: "不能为空",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "不能为空"
            },
            onerror: "不能为空"
        });
    },
    createComboList: function() {
        var objFrm = this;
        //收款部门
        var cmbBillDepartId = new Chenxin.UI.StructCombo({
            param: { op: 'getourdeparts' },
            containerId: '#BillDepartId',
            name: 'BillDepartId',
            inModelType: 'all',
            txtModelName: 'BillDepartName',
            required: true,
            hasPage: true,
            hasSearch: true,
            //initValue:objFrm.defBillDepart,
            colNum: 4,
            tbxWidth: 96
        });
        //签约中心/门店
        var cmbBillPlace = new Chenxin.UI.Combo({
            containerId: '#BillPlaceId',
            name: 'BillPlace',
            inModelType: 'txt',
            tbxWidth: 96,
            colWidth: 80,
            items: eval(centerStr), //comboCommon.ContractCenter,
            required: true
        });
        //付款方式
        var cmbPaybank = new Chenxin.UI.Combo({
            containerId: '#PayBankType',
            name: 'PayBankType',
            inModelType: 'txt',
            tbxWidth: 96,
            colWidth: 80,
            items: [{ val: '划账', txt: '划账' }, { val: '本票', txt: '本票' }, { val: '现金', txt: '现金'}],
            onSelected: function() {
                if (this.getValue() == '划账') {
                    $("#paybank1_tr").show();
                    objFrm.findByName('PayBankName').unFormValidator(false);
                    objFrm.findByName('PayBankNo').unFormValidator(false);
                } else {
                    $("#paybank1_tr").hide();
                    objFrm.findByName('PayBankName').unFormValidator(true);
                    objFrm.findByName('PayBankNo').unFormValidator(true);
                }
            }
        });

        return [cmbBillDepartId, cmbBillPlace,cmbPaybank];
    },
    setDefValue: function(isIn) {
        $('#divIn')[isIn ? 'show' : 'hide']();
        $('#divOut')[isIn ? 'hide' : 'show']();


        var _f = $('#' + (isIn ? 'divIn' : 'divOut')).find('input');
        _f.eq(0).attr('checked', 'checked');

        this.setCDValue(isIn, _f.eq(0).val());

    },
    setCDValue: function(isIn, fundName) {
        this.setTipMsg(isIn ? 1 : -1, fundName);

        var _currentRecord = this.scope.grid.getCurrentRecord();
        var _customer = '';
        var _depart = '';

        switch (fundName) {
            case '上家佣金':
                _customer = 'VenderName';
                _depart = 'VenderDepartId';
                break;
            case '下家佣金':
                _customer = 'BuyerName';
                _depart = 'BuyerDepartId';
                break;
            case '代收房款':
                _customer = 'BuyerName';
                _depart = 'BuyerDepartId';
                break;
            case '代收税费':
                _customer = 'BuyerName';
                _depart = 'BuyerDepartId';
                break;
            case '上家咨询费':
                _customer = '';
                _depart = 'VenderDepartId';
                break;
            case '下家咨询费':
                _customer = '';
                _depart = 'BuyerDepartId';
                break;
            case '上家退佣':
                _customer = 'VenderName';
                _depart = 'VenderDepartId';
                break;
            case '下家退佣':
                _customer = 'BuyerName';
                _depart = 'BuyerDepartId';
                break;
            case '代付房款':
                _customer = 'VenderName';
                _depart = 'VenderDepartId';
                break;
            case '代付税费':
                _customer = '';
                _depart = 'BuyerDepartId';
                break;
        }
        this.findByName('CustomerName').val(_customer ? _currentRecord[_customer] : '');
        this.findByName('BillDepartId').setValue(_depart ? _currentRecord[_depart] : '');
    },
    initEvent: function() {
        var objFrm = this;
        /**************事件：开单日期************/
        $("#txtBillDate").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
        /************事件：收款单点击事件***********/

        this.findByName('InOrOut').click(function() {
            objFrm.setDefValue(this.value == '1' ? true : false);
        });

        this.findByName('FundName').click(function() {
            var str = "上家佣金,下家佣金,代收房款,代收税费";
            objFrm.setCDValue(str.indexOf(this.value) == -1 ? false : true, this.value);
            var str_ds = "代付房款,代付税费";
            if ($("input[name='InOrOut']:checked").val() == '-1' && str_ds.indexOf(this.value) > -1) {
                $("#paybank_tr").show();
                objFrm.findByName('PayBankType').required = true;
            }
            else {
                $("#paybank_tr").hide();
                $("#paybank1_tr").hide();
                objFrm.findByName('PayBankName').unFormValidator(true);
                objFrm.findByName('PayBankNo').unFormValidator(true);
                objFrm.findByName('PayBankType').required = false;
            }
        });


        /* $("#radIn").click(function() {
        $("#divOut").hide();
        $("#divIn").css("display", "inline");
        $("#divIn").find("input[name='FundName']").eq(0).attr("checked", true);
        objFrm.setTipMsg(1, $("input[name='FundName']:checked").val());
        $("#txtCustomerName").val(objFrm.scope.grid.getCurrentRecord().VenderName);
        objFrm.comboList[0].setValue(objFrm.scope.grid.getCurrentRecord().VenderDepartId);
        }); */
        /************事件：付款单点击事件***********/
        /* $("#radOut").click(function() {
        $("#divIn").hide();
        $("#divOut").css("display", "inline");
        $("#divOut").find("input[name='FundName']").eq(0).attr("checked", true);
        objFrm.setTipMsg(2, $("input[name='FundName']:checked").val());
        $("#txtCustomerName").val(objFrm.scope.grid.getCurrentRecord().BuyerName);
        objFrm.comboList[0].setValue(objFrm.scope.grid.getCurrentRecord().BuyerDepartId);
        }); */
        /************事件：开单款项点击事件***********/
        // $("input[name='FundName']").click(function() {
        // objFrm.setTipMsg($("input[name='InOrOut']:checked").val(), $(this).val());
        // });
    }
});

Chenxin.FormCommon.billPaymentForm=function() {
return '<table class="tbl_f"><tr><th style="width:100px">成交编号：</th><td colspan=3><input type=text readonly class="inputbox_n fl" name="ContractCode" /></td></tr><tr><th style="width:80px">合同所属：</th><td colspan=3><input type=text readonly class="inputbox_n fl" name="BargainCompanyName" /></td></tr><tr><th>房屋地址：</th><td colspan=3><input type=text readonly class="inputbox_n fl" style="width:492px" name="HouseAddress" /></td></tr><tr><th>合同标的：</th><td colspan=3><input type=text readonly class="inputbox_n fl" name="BargainPrice" /></td></tr><tr style="height:20px;"><td colspan="4"><hr style="width:100%;"/></td></tr><tr><th>上家客户：</th><td><input type=text readonly class="inputbox_n fl" name="VenderName" /></td><th>上家门店：</th><td><input type=text readonly class="inputbox_n fl" name="VenderDepartName" /></td></tr><tr><th>下家客户：</th><td><input type=text readonly class="inputbox_n fl" name="BuyerName" /></td><th>下家门店：</th><td><input type=text readonly class="inputbox_n fl" name="BuyerDepartName" /></td></tr><tr><th>上家确认佣金：</th><td><input type=text readonly class="inputbox_n fl" name="VRealCommisionFinal" /></td><th>下家确认佣金：</th><td><input type=text readonly class="inputbox_n fl" name="BRealCommisionFinal" /></td></tr><tr style="height:20px;"><td colspan="4"><hr style="width:100%;"/></td></tr><tr><th>开单类型：</th><td colspan=3><input type="radio" name="InOrOut" id="radIn" value="1" checked />收款单<input type="radio" name="InOrOut" id="radOut" value="-1" />付款单</td></tr><tr><th>开单款项：</th><td colspan=3><div id="divIn" style="display:inline"><input type="radio" name="FundName" value="上家佣金" checked />上家佣金<input type="radio" name="FundName" value="下家佣金" />下家佣金<input type="radio" name="FundName" value="代收房款" />代收房款<input type="radio" name="FundName" value="代收税费" />代收税费</div><div id="divOut" style="display:none" ><input type="radio" name="FundName" value="上家咨询费" checked/>上家咨询费<input type="radio" name="FundName" value="下家咨询费" />下家咨询费<input type="radio" name="FundName" value="上家退佣" />上家退佣<input type="radio" name="FundName" value="下家退佣" />下家退佣<input type="radio" name="FundName" value="代付房款" />代付房款<input type="radio" name="FundName" value="代付税费" />代付税费</div></td></tr><tr><td style="background-color:lightgoldenRodYellow;border: 1px dotted;" colspan=4><span id="sMsg" style="color: red;"></span></td></tr><tr><th>开单金额：</th><td colspan=3><input type="text" name="BillMoney" id="txtBillMoney" class="inputbox_n fl" /><span class="fl">元</span><div id="txtBillMoneyTip" style="float: left; margin-left: 5px; width: 250px; height: 26px; line-height: 26px; text-align: left;" ></div><span style="display:none" id="hidCanBill">0</span></td></tr><tr><th style="width:80px">开单日期：</th><td><input type="text" id="txtBillDate" name="BillDate" class="inputbox_n fl" /><div id="txtBillDateTip" style="float: left; margin-left: 5px; width: 80px; height: 26px; line-height: 26px; text-align: left;" ></div></td><th style="width:90px">客户姓名：</th><td><input type="text" name="CustomerName" id="txtCustomerName" class="inputbox_n fl" /><div id="txtCustomerNameTip" style="float: left; margin-left: 5px; width: 80px; height: 26px; line-height: 26px; text-align: left;" ></div></td></tr><tr><th>备注：</th><td colspan=3><textarea name="BillMemo" class="textarea_n" rows=2 cols=80 style="width:492px" /></td></tr><tr><th style="width:80px">收款部门：</th><td><div id="BillDepartId"></div></td><th style="width:90px">签约中心/门店：</th><td><div id="BillPlaceId"></div></td></tr><tr id="paybank_tr" style="display:none;"><th style="width:80px">付款方式：</th><td><div id="PayBankType"></div></td><th style="width:90px"></th><td></td></tr><tr id="paybank1_tr" style="display:none;"><th style="width:80px">划账银行：</th><td><input type=text id="PayBankName" class="inputbox_n fl" name="PayBankName" /><div id="PayBankNameTip" style="float: left; margin-left: 5px; width: 80px; height: 26px; line-height: 26px; text-align: left;" ></div></td><th style="width:90px">划账支付账号：</th><td><input type=text id="PayBankNo" class="inputbox_n fl" name="PayBankNo" /><div id="PayBankNoTip" style="float: left; margin-left: 5px; width: 80px; height: 26px; line-height: 26px; text-align: left;" ></div></td></tr></table>';
};

/**
*个案补证
**/
Chenxin.UI.AddCertificatesFrm = Chenxin.extend(Chenxin.UI.FormCommon, {
    id: "jqmAddCert",
    renderTo: 'jqmAddCert',
    actionUrl: "/service/logic/ShowListBargain.ashx",
    title: "个案补证",
    op: "deallackitems",
    defBBtn: false,
    autoHide:false,
    autoAlertSucc:false,
    createBBtn: function() {
        return [{text: '提交',handler: this.frmSubmit,scope: this},
                {text: '取消',handler: this.hide,scope: this}];
    },
    frmSubmit: function() {

        //资料一齐全时间判断
        if (this.comboList[0].getValue() == "false") {
            if ($("#txtCompleteDate1").val() == "") {
                alert("请输入资料一的齐全时间");
                return false;
            } 
        }
        //资料二齐全时间判断
        if (this.comboList[1].getValue() == "false") {
            if ($("#txtCompleteDate2").val() == "") {
                alert("请输入资料二的齐全时间");
                return false;
            } 
        }
        this.save();
    },
    beforeFitData: function(json) {
        //资料一齐全时间
        if (json.CompleteDate1 != undefined) {
            json.CompleteDate1 = json.CompleteDate1.split(" ")[0];
        }
        //资料二齐全时间
        if (json.CompleteDate2 != undefined) {
            json.CompleteDate2 = json.CompleteDate2.split(" ")[0];
        }
        //资料项目一
        if (json.IsLackItem1 != undefined) {
            json.IsLackItem1 = String(json.IsLackItem1);
        }
        //资料项目二
        if (json.IsLackItem2 != undefined) {
            json.IsLackItem2 = String(json.IsLackItem2);
        }
    },
    saveSucc: function(data, msg) {
        if (data == "Nodata") {
            alert(msg);
            $("#txtIntentionCode").focus();
            //已经关联
        } else if (data == "Exist") {
            alert(msg);
            $("#txtIntentionCode").focus();
        } else {
            alert(msg);
            this.addCertFrm.hide();
        }
        delete this.addCertFrm.additionalParam.IntentionCode;
        delete this.addCertFrm.additionalParam.ContractCode;
    },
    createForm: function() {
        return formCommon.AddCertificatesFrm(this.createLackItems1(), this.createLackItems2());
    },
    createLackItems1: function() {
        var strRet = "";
        var strLen = "140px";
        var jsonData = checkboxCommon.LackItems1;
        strRet = strRet + "<fieldset style='border:1px solid silver;margin: 0pt 0pt 10px 18px;width:520px;'>";
        //strRet = strRet + "<legend align='center'>缓发奖金全部项目</legend>";
        strRet = strRet + "<ul>";
        for (var idxCnt = 0; idxCnt < jsonData.length; idxCnt++) {
            if (jsonData[idxCnt].txt.length > 10) {
                strLen = "260px";
            } else {
                strLen = "130px";
            }
            strRet = strRet + "<li style='display:inline;float:left;width:" + strLen + ";'>";
            strRet = strRet + '<input type="checkbox" name="LackItems1" value="' + jsonData[idxCnt].val + '" />' + jsonData[idxCnt].txt;
            strRet = strRet + "</li>";
        }
        strRet = strRet + "<li>";
        strRet = strRet + "<div style='display:block'><span class='fl'>其他</span><input name='LackOthers1' style='width:480px;margin:0 0 5px' type=text class='inputbox_n fl'/></div>";
        strRet = strRet + "</li>";
        strRet = strRet + "</ul>";
        strRet = strRet + "</fieldset>";
        return strRet;
    },
    createLackItems2: function() {
        var strRet = "";
        var jsonData = checkboxCommon.LackItems2;
        strRet = strRet + "<fieldset style='border:1px solid silver;width:520px;margin-left:18px'>";
        //strRet = strRet + "<legend align='center'>缓发买卖奖金200元项目</legend>";
        strRet = strRet + "<ul>";
        var strLen = "140px";
        for (var idxCnt = 0; idxCnt < jsonData.length; idxCnt++) {
            if (jsonData[idxCnt].txt.length > 10) {
                strLen = "260px";
            } else {
                strLen = "130px";
            }
            strRet = strRet + "<li style='display:inline;float:left;width:" + strLen + ";'>";
            strRet = strRet + '<input type="checkbox" name="LackItems2" value="' + jsonData[idxCnt].val + '" />' + jsonData[idxCnt].txt;
            strRet = strRet + "<li>";
        }
        strRet = strRet + "</ul>";
        strRet = strRet + "</fieldset>";
        return strRet;
    },
    createComboList: function() {
        //材料一齐全判断
        var cmbIsLackItem1 = new Chenxin.UI.Combo({
            containerId: '#IsLackItem1',
            name: 'IsLackItem1',
            required: true,
            tbxWidth: 120,
            colWidth: 80,
            items: comboCommon.IsLackItem,
            onSelected: function() {
                if (this._val == this.defVal) {
                    $("#txtCompleteDate1").attr("disabled", false);
                } else if (this._val == "true") {
                    $("#txtCompleteDate1").val("");
                    $("#txtCompleteDate1").attr("disabled", true);
                } else {
                    $("#txtCompleteDate1").attr("disabled", false);
                    $("input[name='LackItems1']").attr("checked", false);
                    $("input[name='LackOthers1']").val("");
                }
            },
            afterSetValue: function() {
                if (this._val == this.defVal) {
                    $("#txtCompleteDate1").attr("disabled", false);
                } else if (this._val == "true") {
                    $("#txtCompleteDate1").val("");
                    $("#txtCompleteDate1").attr("disabled", true);
                } else {
                    $("#txtCompleteDate1").attr("disabled", false);
                }
            }
        });
        //材料二齐全判断
        var cmbIsLackItem2 = new Chenxin.UI.Combo({
            containerId: '#IsLackItem2',
            name: 'IsLackItem2',
            required: true,
            tbxWidth: 120,
            colWidth: 80,
            items: comboCommon.IsLackItem,
            onSelected: function() {
                if (this._val == this.defVal) {
                    $("#txtCompleteDate2").attr("disabled", false);
                } else if (this._val == "true") {
                    $("#txtCompleteDate2").val("");
                    $("#txtCompleteDate2").attr("disabled", true);
                } else {
                    $("#txtCompleteDate2").attr("disabled", false);
                    $("input[name='LackItems2']").attr("checked", false);
                }
            },
            afterSetValue: function() {
                if (this._val == this.defVal) {
                    $("#txtCompleteDate2").attr("disabled", false);
                } else if (this._val == "true") {
                    $("#txtCompleteDate2").val("");
                    $("#txtCompleteDate2").attr("disabled", true);
                } else {
                    $("#txtCompleteDate2").attr("disabled", false);
                }
            }
        });
        return [cmbIsLackItem1, cmbIsLackItem2];
    },
    initEvent: function() {
        var objFrm = this;
        /*************事件：齐全时间1*************/
        $("#txtCompleteDate1").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
        $("#txtCompleteDate1").attr("disabled", true);
        /*************事件：齐全时间2*************/
        $("#txtCompleteDate2").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
        $("#txtCompleteDate2").attr("disabled", true);
        /*************事件：意向书编号检查*************/
        $("#txtIntentionCode").blur(function() {
            if ($(this).val() == "") {
                return false;
            }
            Chenxin.ajax({
                type: "get",
                dataType: "json",
                url: objFrm.actionUrl,
                data: { op: 'chkintentioncode', ContractId: objFrm.scope.currentId, IntentionCode: $(this).val() },
                onSuccess: function(data, msg) {
                    //不存在
                    if (data == "Nodata") {
                        alert(msg);
                        $("#txtIntentionCode").focus();
                        //已经关联
                    } else if (data == "Exist") {
                        alert(msg);
                        $("#txtIntentionCode").focus();
                    }
                }
            });
        });
    }
});

/*
**上传文件窗体
*/
Chenxin.UI.UploadFileFrm = Chenxin.extend(Chenxin.UI.FormCommon, {
    id: "jqmAddAtt",
    renderTo: 'jqmAddAtt',
    actionUrl: "/service/logic/ShowListBargain.ashx",
    title: "上传附件",
    op: "uploadatt",
    createForm: function() {
        return '<table class="tbl_f"><tr><th style="width:60px">说明：</th><td><textarea class="fl" cols=90 rows=3 name = "Remark" /></td></tr><tr><th>附件：</th><td><input type="file" name="UploadAttachment" id="UploadAttachment" /></td></tr>';
    },
    defBBtn: false,
    createBBtn: function() {
        return [{text: '提交',handler: this.frmSubmit,scope: this},
                {text: '取消',handler: this.hide,scope: this}];
    },
    frmSubmit: function() {

        $("#UploadAttachment").uploadifyUpload();
    },
    initEvent: function() {

        var _this = this;
        //上传附件Flash
        $("#UploadAttachment").uploadify({
            uploader: '/js/Plug/uploadify.swf',
            script: '/service/logic/ShowListBargain.ashx?op=fileupload',
            cancelImg: '/images/cancel.png',
            buttonImg: '/images/fileupload.png',
            auto: false,
            multi: false,
            sizeLimit: 1048576,
            height: 24,
            width: 190,
            fileDesc: '支持格式:xls,doc,pdf,rar,zip,jpg,xlsx,docx',
            fileExt: '*.xls;*.doc;*.pdf;*.rar;*.zip;*.jpg;*.xlsx;*.docx',
            wmode: 'transparent',
            onComplete: function(event, queueID, fileObj, response, data) {
                if (response) {
                    try {
                        eval("var json=" + response);
                        if (json.success == 1) {
                            if (data.fileCount == 0) {
                                _this.filename = json.data.filename;
                                _this.savename = json.data.savename;
                                _this.save();
                                delete _this.filename;
                                delete _this.savename;
                            }
                        } else if (json.success == 0) {
                            alert(json.msg);
                        } else {
                            alert(json.msg);
                            window.location.href = Chenxin.loginUrl;
                        }
                    } catch (e) {
                        alert('返回数据格式错误，文件上传失败！');
                    }
                }
            },
            onError: function(event, queueID, fileObj, errorObj) {
                alert("文件:" + fileObj.name + "上传失败(" + errorObj.info + ")");
            }
        });
    }
});

/*
* 佣收调整
*/
Chenxin.UI.AdjCommisionForm = Chenxin.extend(Chenxin.UI.FormCommon,{
    id: "jqmCommAdj",
    renderTo: 'jqmCommAdj',
    actionUrl: "/service/logic/ShowListBargain.ashx",
    title: "佣收调整",
    op: "adjcomm",
    defBBtn: true,
    createForm:function(){
        var strRet = "";
        strRet = strRet + '<table class="tbl_f">';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th style="width:100px">成交编号：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" readonly name="ContractCode" style="width:126px" /></td>';
        strRet = strRet + '<th style="width:100px">业绩归属：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" readonly name="AppDepart" style="width:126px" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>房屋地址：</th>';
        strRet = strRet + '<td colspan="3"><input type="text" class="inputbox_n fl" style="width:419px" readonly name="HouseAddress" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>上家客户：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" readonly name = "VenderName" style="width:126px" /></td>';
        strRet = strRet + '<th>下家客户：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" readonly name = "BuyerName" style="width:126px" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>调整内容：</th>';
        strRet = strRet + '<td colspan="3">';
        strRet = strRet + '<input type="radio"  name = "AdjustType" value="10" />上家确认收入';
        strRet = strRet + '<input type="radio"  name = "AdjustType" value="20" />下家确认收入';
        strRet = strRet + '<input type="radio"  name = "AdjustType" value="30" />上家咨询费';
        strRet = strRet + '<input type="radio"  name = "AdjustType" value="40" />下家咨询费';
        strRet = strRet + '</td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>调整事由：</th>';
        strRet = strRet + '<td><div id="AdjustReason"></div></td>';
        strRet = strRet + '<th><span id="hdType" style="display:none">折佣类型：</span></th>';
        strRet = strRet + '<td><div id="DiscountType" style="display:none"></div></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr">';
        strRet = strRet + '<th>调整金额：</th>';
        strRet = strRet + '<td colspan="3">';
        strRet = strRet + '<input type="text" class="inputbox_n fl" name = "AdjustMoney" id="AdjAdjustMoney" style="width:126px"/><span class="fl">元</span>';
        strRet = strRet + '<div id="AdjAdjustMoneyTip" style="float: left; margin-left: 5px; width: 180px; height: 26px; line-height: 26px; text-align: left;" >';
        strRet = strRet + '</td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>调整前金额：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" readonly name = "BeforeAdjust" id="AdjBeforeAdjust" style="width:126px" /><span class="fl">元</span></td>';
        strRet = strRet + '<th>调整后金额：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" readonly name = "AfterAdjust" id="AdjAfterAdjust" style="width:126px" /><span class="fl">元</span></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr">';
        strRet = strRet + '<th>实际收付金额：</th>';
        strRet = strRet + '<td colspan="3"><input type="text" class="inputbox_n fl" readonly name = "PayedMoney" id="AdjPayedMoney" style="width:126px" /><span class="fl">元</span></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>调整说明：</th>';
        strRet = strRet + '<td colspan=3><textarea class="textarea_n fl" cols="80" rows="7" style="width:420px" name="AdjustDescription" id="AdjAdjustDescription" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th></th>';
        strRet = strRet + '<td colspan=3><div id="AdjAdjustDescriptionTip" style="float: left; margin-left: 5px; width: 180px; height: 26px; line-height: 26px; text-align: left;" ></div></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th><a href="javascript:void(0)" id="aShowAdjHis">显示调整历史</a></th>';
        strRet = strRet + '<td colspan=3></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<td colspan="4" style="width:560px" align="center"><div style="width:95%;margin-left:15px"><div id="divHistory" style="display:none;"></div></div></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '</table>';
        return strRet;
    },
    createComboList:function(){
        var objFrm = this;
        //调整事由
        var cmbAdjustReason =new Chenxin.UI.Combo({
            containerId: '#AdjustReason',
            tbxWidth: 95,
            required:true,
            items: comboCommon.AdjustReason,
            onSelected:function(){
                if( this._val == "增加收入" || this._val == this.defVal ){
                    if(objFrm.comboList.length > 1){
                        objFrm.comboList.splice(1,1);
                    }
                    $("#hdType").hide();
                    $("#DiscountType").hide();
                }else{
                    if(objFrm.comboList.length == 1){
                        objFrm.comboList.push(objFrm.cmbDiscountType);
                    }
                    $("#hdType").show();
                    $("#DiscountType").show();
                }
            }
        });
        //折佣类型
        this.cmbDiscountType =new Chenxin.UI.Combo({
            containerId: '#DiscountType',
            tbxWidth: 95,
            required:true,
            items: comboCommon.DiscountType
        });
        return[cmbAdjustReason];
    },
    initFormValidator:function(){
         //调整金额
		 var _this=this;
        $("#AdjAdjustMoney").formValidator({
            validatorgroup: this.id,
            onshow: "请输入调整金额！",
            onfocus: "调整金额为必输项目",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "调整金额不能为空！"
            },
            onerror: "调整金额不能为空！"
        }).regexValidator({
            regexp: "money",
            datatype: "enum",
            onerror: "非金额格式！"
        }).functionValidator({ //数字验证
            fun:function(val,elem) { 
				val=Chenxin.Fn.fullToHalfChar(val);
				var _vv=parseFloat(_this.findByName('BeforeAdjust').val());
				if(parseFloat(val)+_vv<0){
					return '调整后金额不能为负数';
				}
				return true;
			}, 
			onerror: "请输入非0数字"
        });
        //调整说明
        $("#AdjAdjustDescription").formValidator({
            validatorgroup: this.id,
            onshow: "请输入调整说明！",
            onfocus: "调整说明为必输项目",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "调整说明不能为空！"
            },
            onerror: "调整说明不能为空！"
        });
    },
    initEvent:function(){
        var objFrm = this;
        /***********事件：调整内容选择**********/
        $("input[name='AdjustType']").click(function(){
            objFrm.setMoney($(this).val());
        });
        /***********事件：显示调整与否**********/
        $("#aShowAdjHis").click(function(){
            if( $(this).text() == "显示调整历史" ){
                $("#divHistory").show();
                $(this).text("隐藏调整历史");
                objFrm.grid.reload({ContractCode:objFrm.scope.grid.getCurrentRecord().ContractCode});
            }else{
                $("#divHistory").hide();
                $(this).text("显示调整历史");
            }
        });
        /***********事件：调整金额失去焦点**********/
        $("#AdjAdjustMoney").blur(function(){
            if( $(this).val() == ""){
                $("#AdjAfterAdjust").val("");
            }else{
                if( $(this).val().isNum()){
                    $("#AdjAfterAdjust").val( parseFloat($("#AdjBeforeAdjust").val()) + parseFloat($("#AdjAdjustMoney").val()) );
                }else{
                    $("#AdjAfterAdjust").val("");
                }
            }
        });
    },
    reset:function(){
        Chenxin.UI.AdjCommisionForm.superclass.reset.call(this);
        $("#divHistory").hide();
        $("#aShowAdjHis").text("显示调整历史");
        if(this.comboList.length > 1){
            this.comboList.splice(1,1);
        }
        $("#hdType").hide();
        $("#DiscountType").hide();
    },
    setMoney:function(AdjustType){
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            async: false,
            url: this.actionUrl,
            data: { op: 'getmomey', ContractId: this.scope.grid.getCurrentRecord().ContractId,AdjustType:AdjustType },
            onSuccess: function(data, msg) {
                $("#AdjPayedMoney").val(data.PayedMoney);
                $("#AdjBeforeAdjust").val(data.BeforeMoney);
                if( $("#AdjAdjustMoney").val() != "" ){
                    $("#AdjAfterAdjust").val(data.BeforeMoney +  parseFloat($("#AdjAdjustMoney").val()) );
                }
            }
        });
    },
    createGrid:function(){
        return new Chenxin.UI.JsonGrid({
            actionUrl: this.actionUrl + '?op=gethistory',
            pageSize: 10,
            renderTo: 'divHistory',
            hasCheckBox: false,
            autoLoad: false,
            scope: this,
            height:90,
            width:550,
            id: 'HistoryList',
            title: '佣收调整历史',
            scope: this,
            columns: {
                ContractCompany: {
                    width: 100,
                    head: "合同所属公司",
                    sortable: true
                },
                ContractCode: {
                    width: 100,
                    head: "成交编号",
                    sortable: true
                },
                AdjustType: {
                    width: 100,
                    head: "调整类型",
                    sortable: true
                },
                DiscountType: {
                    width: 100,
                    head: "折佣类型",
                    sortable: true
                },
                AdjustReason: {
                    width: 122,
                    head: "调整事由",
                    sortable: true
                },
                AdjustMoney : {
                    width: 80,
                    head: "调整金额",
                    sortable: true
                },
                BeforeAdjust : {
                    width: 80,
                    head: "调整前金额",
                    sortable: true
                },
                AfterAdjust : {
                    width: 80,
                    head: "调整后金额",
                    sortable: true
                },
                AdjustDescription : {
                    width: 400,
                    head: "调整说明",
                    sortable: true
                },
                AddDepart: {
                    width: 130,
                    head: "调整部门",
                    sortable: true
                },
                AddEmployee: {
                    width: 80,
                    head: "调整人员",
                    sortable: true
                },
                Addtime: {
                    width: 80,
                    head: "调整时间",
                    sortable: true
                }
            }
        });
    },
    initComponent:function(){
        Chenxin.UI.AdjCommisionForm.superclass.initComponent.call(this);
        this.grid = this.createGrid();
    }
});

/*
* 应收登记
*/
Chenxin.UI.RegIncomeForm = Chenxin.extend(Chenxin.UI.FormCommon,{
     id: "jqmRegIncome",
    renderTo: 'jqmRegIncome',
    actionUrl: "/service/logic/ShowListBargain.ashx",
    title: "应收登记",
    op: "regincome",
    defBBtn: true,
    jqmWidth:510,
    createForm:function(){
        var strRet = "";
        strRet = strRet + '<table class="tbl_f">';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th style="width:100px">成交编号：</th>';
        strRet = strRet + '<td style="width:150px"><input type="text" class="inputbox_n fl" readonly name="ContractCode" style="width:126px" /></td>';
        strRet = strRet + '<th style="width:100px">合同标的：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" readonly name="BargainPrice" style="width:126px" /><span class="fl">元</span></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>房屋地址：</th>';
        strRet = strRet + '<td colspan="3" style="width:100px"><input type="text" class="inputbox_n fl" style="width:372px" readonly name="HouseAddress" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>上家客户：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" readonly name = "VenderName" style="width:126px" /></td>';
        strRet = strRet + '<th>下家客户：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" readonly name = "BuyerName" style="width:126px" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th>应收类型：</th>';
        strRet = strRet + '<td><div id="RegIncomeType"></div></td>';
        strRet = strRet + '<th>应收金额：</th>';
        strRet = strRet + '<td><input type="text" class="inputbox_n fl" name = "RegIncomeMoney" style="width:126px" id="RegIncomeMoney" /></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<th></th>';
        strRet = strRet + '<td></td>';
        strRet = strRet + '<th></th>';
        strRet = strRet + '<td><div id="RegIncomeMoneyTip" style="float: left; margin-left: 5px; width: 130px; height: 26px; line-height: 26px; text-align: left;" ></div></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '<tr>';
        strRet = strRet + '<td colspan="4" align="center"><div style="width:400px;margin-left:25px"><div id="divIncomeHistory"></div></div></td>';
        strRet = strRet + '</tr>';
        strRet = strRet + '</table>';
        return strRet;
    },
    createComboList:function(){
        var objFrm = this;
        var RegIncomeType = new Chenxin.UI.Combo({
            containerId: '#RegIncomeType',
            name:'IncomeType',
            tbxWidth: 95,
            required: true,
            addPleaseSelected:false,
            items: comboCommon.RegIncomeType,
            onSelected:function(){
                objFrm.grid.reload({ContractId:objFrm.scope.grid.getCurrentRecord().ContractId,IncomeType:this._val});
            }
        });
        return [RegIncomeType]
    },
    initFormValidator:function(){
        //应收金额
        $("#RegIncomeMoney").formValidator({
            validatorgroup: this.id,
            onshow: "请输入应收金额！",
            onfocus: "应收金额为必输项目",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "应收金额不能为空！"
            },
            onerror: "应收金额不能为空！"
        }).regexValidator({
            regexp: "money",
            datatype: "enum",
            onerror: "非有效金额格式！"
        });
    },
    createGrid:function(){
        return new Chenxin.UI.JsonGrid({
            actionUrl: this.actionUrl + '?op=getincomehistory',
            pageSize: 10,
            renderTo: 'divIncomeHistory',
            hasCheckBox: false,
            autoLoad: false,
            scope: this,
            height:90,
            width:440,
            id: 'IncomeHistoryList',
            title: '应收金额历史',
            scope: this,
            columns: {
                IncomeType: {
                    width: 100,
                    head: "应收类型",
                    sortable: true
                },
                AddTime: {
                    width: 100,
                    head: "建档时间",
                    sortable: true
                },
                AddUserName: {
                    width: 100,
                    head: "建档人",
                    sortable: true
                },
                Income: {
                    width: 113,
                    head: "应收金额",
                    sortable: true
                }
            }
        });
    },
    show:function(){
        this.grid.reload({ContractId:this.scope.grid.getCurrentRecord().ContractId,IncomeType:"代收房款"});
        return Chenxin.UI.RegIncomeForm.superclass.show.call(this);
    },
    initComponent:function(){
        Chenxin.UI.RegIncomeForm.superclass.initComponent.call(this);
        this.grid = this.createGrid();
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(document).ready(function() {
    var ApplyInfoMgr = new Chenxin.UI.ApplyInfoManage();
});